home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 163 < prev    next >
Text File  |  1996-08-06  |  3KB  |  60 lines

  1. Newsgroups: comp.std.c
  2. Path: phcoms4.seri.philips.nl!panther!baynes
  3. From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
  4. Subject: Re: atexit() and return from main()
  5. Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
  6. Message-ID: <DLMLL6.A0H@ukpsshp1.serigate.philips.nl>
  7. Date: Tue, 23 Jan 1996 08:43:54 GMT
  8. References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> <4diicg$i9e@lyra.csx.cam.ac.uk> <TANMOY.96Jan22084309@qcd.lanl.gov>
  9. Organization: Philips Semiconductors, Southampton, UK
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
  13. : --text follows this line--
  14. : In article <DLKrx7.6p6@ukpsshp1.serigate.philips.nl>
  15. : baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes: 
  16. : <snip>
  17. :    <snip>
  18. :    :    main() calls setjmp() and then calls exit().  An atexit() function
  19. :    :    calls longjmp() and returns to main().  This repeats (or does it?)
  20.  
  21. :    : Neither of these is permitted in any sense that I understand!
  22. :    : 7.10.4.3: If more than one call to the exit function is executed by
  23. :    : a program, the behaviour is undefined. No `permission by omission'
  24. :    : that I can see.
  25.  
  26. :    In this example what happens if no second call to exit is been made (after
  27. :    longjumping back to main the program does not attempt to call exit again -
  28. :    instead it keeps executing indefinately)?
  29.  
  30. : I don't understand the question: are you asking what happens if a
  31. : program keeps executing indefinitely? Well, it just keeps executing
  32. : indefinitely. After that infinite period, the rest of the exit
  33. : processing happens and a return status is indicated to the rts.
  34.  
  35. The question I am asking is if:
  36.     main() calls setjmp() and then calls exit().  An atexit() function
  37.     calls longjmp() and returns to main().  main() then continues to
  38.     execute other code. Is the execution of this code defined behaviour
  39.     (so long as no attempt is made to exit again)?
  40.  
  41. [Note: There is a large class of programs that never exit at all (including 
  42. embeded systems and some daemons). They either have the power turned off or are
  43. signalled to death. These are usually accepted as having well defined 
  44. behaviour (at least untill the point the power goes of). I agree it would
  45. be perverse of such a program to make exactly one call to exit and then
  46. abandon it by a long jump from an atexit function to main. One can also 
  47. construct programs that do this longjump and terminate later by calling abort.
  48. However I think it is reasonable to ask if it is defined what happens after the 
  49. longjump in the example is made.]
  50.  
  51. A related question - does undefined behaviour invalidate (make undefined) all 
  52. defined behaviour that has gone before? If so does this mean that any program 
  53. that does not exit() or return from main have any defined behaviour?
  54.  
  55. --
  56. Stephen Baynes                              baynes@mulsoc2.serigate.philips.nl
  57. Philips Semiconductors Ltd
  58. Southampton                                 My views are my own.
  59. United Kingdom
  60.